package JZ64_滑动窗口的最大值;

import java.util.*;
public class Solution {
    private PriorityQueue<Integer> maxQueue = new PriorityQueue<>(new Comparator<Integer>() {
        @Override
        public int compare(Integer o1, Integer o2) {
            return o2 - o1;
        }
    });
    private ArrayList<Integer> list = new ArrayList<>();
    public ArrayList<Integer> maxInWindows(int [] num, int size) {
        if (num == null || num.length <= 0 || size <= 0 || size > num.length){
            return list;
        }

        int count = 0;
        for (; count < size; count++){
            maxQueue.offer(num[count]);
        }

        while (count < num.length){
            list.add(maxQueue.peek());
            maxQueue.remove(num[count - size]);
            maxQueue.offer(num[count]);
            count++;
        }
        list.add(maxQueue.peek());
        return list;
    }
}